<?php



defined('BASEPATH') OR exit('No direct script access allowed');

include 'linkdatabase.php';
include 'findInDatabase.php';


class Books extends CI_Controller {
  public function index(){
		$type=$_GET['type'];
    $status="确认完成";

		
    // $item=array('m_name','m_expression','m_pay','m_place','m_time','m_state ','m_date','sellername','contect','contectId');
    $data=array();
    $item=array();
    $link = linkdatabase::link();
    @mysqli_select_db($link, "witkey");

		if($type==1){
      $sql="SELECT * FROM mission WHERE `m_state`='$status'";
		  $result = mysqli_query($link, $sql);
		  $num = mysqli_num_rows($result);
			for($i=0; $i<$num;$i++){
				$row= mysqli_fetch_assoc($result);
			  $name=findInDatabase::findname($row['u_id']);
				$item['jobname']=$row['m_name'];
				$item['jobdetail']=$row['m_expression'];
				$item['price']=$row['m_pay'];
				$item['jobadress']=$row['m_place'];
				$item['time']=$row['m_time'];
				$item['status']=$row['m_state'];
				$item['date']=$row['m_date'];
				$item['sellername']=$name['name'];
				$item['contect']=$name['contact'];
				$item['contectId']=$name['contactId'];
				$data[$i]=$item;
			}

			header('Content-Type:text/json');
			echo json_encode($data);
			
		}else{
      $sql="SELECT * FROM buybook WHERE `status`='$status'";
		  $result = mysqli_query($link, $sql);
		  $num = mysqli_num_rows($result);
			for($i=0; $i<$num;$i++){
				$row= mysqli_fetch_assoc($result);
			  $name=findInDatabase::findname($row['uid']);
				$item['title']=$row['title'];
				$item['author']=$row['author'];
				$item['date']=$row['date'];
				$item['status']=$row['status'];
				$item['buyername']=$name['name'];
				$item['contect']=$name['contact'];
				$item['contectId']=$name['contactId'];
				$data[$i]=$item;
			}
			// header(	'Content-Type:text/json');
			echo json_encode($data);
		}


			

  }
}

